<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="./asset/css/reset.css">
  <link rel="stylesheet" href="./asset/css/self-evaluation.css">
  <title>李山投资-员工填写个人总结</title>
</head>

<body>
  <div class="wrapper">d
    <p class="works">
      <button id="submit" class="works__btn">提交</button>
      <button id="download" class="works__btn">导出</button>
    </p>
    <div id="pdf">
      <p class="logo">
        <img src="./asset/images/logo.png" alt="" width="210px" height="53px">
      </p>
      <form class="main">
        <h1 class="title">员工填写个人总结<span class="tip">LSHR-03-B</span></h1>
        <div class="sheet">
          <div class="sheet__desc clearfix">
            <div class="sheet__desc__item">姓名</div>
            <div class="sheet__desc__item">
              <input class="input" type="text" name="uname" placeholder="请填写姓名" id="uname">
            </div>
            <div class="sheet__desc__item">入职日期</div>
            <div class="sheet__desc__item">
              <input class="input" type="text" name="joinedDate" placeholder="请填写入职日期" id="joinedDate">
            </div>
            <div class="sheet__desc__item">试用期薪资</div>
            <div class="sheet__desc__item">
              <input class="input" type="text" name="probateSalary" placeholder="请填写试用期薪资" id="probateSalary">
            </div>
            <div class="sheet__desc__item">转正日期</div>
            <div class="sheet__desc__item">
              <input class="input" type="text" name="qualifiedDate" placeholder="请填写转正日期" id="qualifiedDate">
            </div>
          </div>
          <div class="sheet__content">
            <div class="sheet__content__item">
              <h2>一、对公司的认识</h2>
              <textarea name="company" id="c1" class="textarea" placeholder="请填写对公司的认识" maxlength="500"></textarea>
            </div>
            <div class="sheet__content__item">
              <h2>二、对本岗位的认识</h2>
              <textarea name="job" id="c2" class="textarea" placeholder="请填写对本岗位的认识" maxlength="500"></textarea>
            </div>
            <div class="sheet__content__item">
              <h2>三、对个人在本岗位能力发挥的认识</h2>
              <textarea name="ability" id="c3" class="textarea" placeholder="请填写对个人在本岗位能力发挥的认识" maxlength="500"></textarea>
            </div>
            <div class="sheet__content__item">
              <h2>四、其他合理化建议</h2>
              <textarea name="suggest" id="c4" class="textarea" placeholder="请填写其他合理化建议" maxlength="500"></textarea>
            </div>
            <p class="sheet__footer">备注：总结字数不限，如篇幅不够可附页。</p>
          </div>
        </div>
      </form>
    </div>
  </div>
</body>
<script src="./js/jquery-1.8.3.min.js"></script>
<script>
  var type = /type=(\w+)/gi.exec(window.location.href);
  var empid = /empid=(\w+)/gi.exec(window.location.href);
  var username = /username=([\u4E00-\u9FA5]+)/gi.exec(decodeURIComponent(window.location.href));
  var station = /station=([\u4E00-\u9FA5]+)/gi.exec(decodeURIComponent(window.location.href));
  var tofulldate = /tofulldate=([0-9\-]+)/g.exec(window.location.href);
  var entryDate= /entryDate=([0-9\-]+)/g.exec(window.location.href);
  // var baseUrl = 'http://192.168.22.45:5526/';
  // var baseUrl = 'http://192.168.3.26:5526/';
  var baseUrl = 'http://report.wsloan.com:5526/EmployeeSystem';

  if (username) {
    username = username[1];
  }

  if (station) {
    station = station[1];
  }

  if (empid) {
    empid = empid[1];
  } else {
    // 没有empid的处理
  }

  if(tofulldate){
    tofulldate = tofulldate[1];
  }

  if(entryDate){
    entryDate = entryDate[1];
  }

  console.log(username);
  if (type) {
    type = type[1];
    if (type == 'edit') {
      $('#submit').show();
      $('#uname').val(username).attr('disabled', 'true');

      if(entryDate){
        $('#joinedDate').val(entryDate).attr('disabled', 'true');
      }

      if(tofulldate){
        $('#qualifiedDate').val(tofulldate).attr('disabled', 'true');
      }

    } else if (type == 'preview') {
      $('.input,.radio,.textarea').attr('disabled', 'true');
      $('#download').show();
      getSelfAss();
    } else {
      // 非法参数值处理
    }
  } else {
    // 没有type的处理
  }

  // 获取自我评价
  function getSelfAss(){
    $.ajax({
      url: baseUrl + 'show/self.htmls',
      type:'get',
      data: {
        empid: empid
      },
      success: function(res){
        var data = res.data
        console.log(res)
        if(res.code === 0 && data){
          $('#uname').val(data.username || ' ')
          $('#joinedDate').val(data.entryDate || ' ')
          $('#probateSalary').val(data.salary || ' ')
          $('#qualifiedDate').val(data.tofulldate || ' ')

          $('#c1').val(data.content1 || ' ')
          $('#c2').val(data.content2 || ' ')
          $('#c3').val(data.content3 || ' ')
          $('#c4').val(data.content4 || ' ')
        }else{
          alert(res.msg)
        }
      },
      error: function(res){
        alert('请求失败')
      }
    })
  }

  // 提交
  $('#submit').on('click', function(e) {
    e.stopPropagation();
    e.preventDefault();
    var content1 = $('#c1').val();
    var content2 = $('#c2').val();
    var content3 = $('#c3').val();
    var content4 = $('#c4').val();
    // return
    if (!content1 || !content2 || !content3 || !content4) {
      alert('还有未填写的项目');
      return false;
    }
    console.log({
      empid: empid,
      content1: content1,
      content2: content2,
      content3: content3,
      content4: content4
    });
    $.ajax({
      url: baseUrl + 'insert/selfevalution.htmls',
      type: 'post',
      dataType: 'json',
      data: {
        empid: empid,
        content1: content1,
        content2: content2,
        content3: content3,
        content4: content4
      },
      success: function(data) {
        var url = window.location.href
        if (data.code === 0) {
          alert(data.msg);
          url = url.replace(/type=edit/, 'type=preview');
          window.location.replace(url)
        }
      },
      error: function(error) {
        console.log(error);
        alert('请求失败');
      }
    });
  });
</script>
<script src="./js/jspdf.debug.js"></script>
<!-- <script src="./js/jspdf.min.js"></script> -->
<script src="./js/download.js"></script>

</html>
